﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using ELearningSystem.UI.ContentServiceReference;
using ContentManager = ELearningSystem.UI.ContentServiceReference.ContentServiceSoapClient;
using AnswerManager = ELearningSystem.UI.AnswerServiceReference.AnswerServiceSoapClient;
using TreeContent = ELearningSystem.UI.ContentServiceReference.TreeContentDAO;
using VideoContent = ELearningSystem.UI.ContentServiceReference.VideoContentDAO;
using Practice = ELearningSystem.UI.ContentServiceReference.PracticeDAO;
using Content = ELearningSystem.UI.ContentServiceReference.ContentDAO;
namespace ELearningSystem.UI.AdminUI
{
    public partial class AddVideoUI : System.Web.UI.Page
    {
        private TreeContent treeContent;
        private ContentManager contentManager = new ContentManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetNoStore();
            if (!IsPostBack)
            {
                treeContent = (TreeContent)Session["Content"];
                topicLabel.Text = treeContent.ParentNode.Text;
                saveResponseLabel.Text = "";
                saveResponseLabel.ForeColor = Color.Green;
                saveResponseLabel.Text = Request.QueryString["message"];

            }

        }

        protected void saveButton_Click(object sender, EventArgs e)
        {
            treeContent = (TreeContent)Session["Content"];
            VideoContent video = new VideoContent();
            treeContent.Text = titleTextBox.Text;
            video.Text = titleTextBox.Text;
            video.Link = linkTextBox.Text;
            List<DescriptionDAO> descriptions = new List<DescriptionDAO>() { new DescriptionDAO() { Text = descriptionTextBox.Text } };
            List<MaterialDAO> materials = new List<MaterialDAO>() { new MaterialDAO() { Link = materialTextBox.Text } };
            List<ReferenceDAO> references = new List<ReferenceDAO>() { new ReferenceDAO() { Link = referencesTextBox.Text } };
            video.Descriptions = descriptions;
            video.Materials = materials;
            video.References = references;

            Content content = new Content();
            content.IsVideo = true;
            content.Video = video;
            treeContent.Content = content;
            bool isSaved = contentManager.SaveOrUpdate(treeContent);
            if (isSaved)
            {
                Response.Redirect("~/AdminUI/AddVideoUI.aspx?message=Successfully Saved & flag=true");
            }
            else
            {
                saveResponseLabel.ForeColor = System.Drawing.Color.Red;
                saveResponseLabel.Text = "Saving Failed!!";
            }
        }

        protected void doneButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AdminUI/AdminHomePageUI.aspx");
        }
    }
}